
addpath('gpml-matlab-v3.1-2010-09-27');
startup;

n_xpts = 20;
n_trials = 3;

n_class = 3; % kludge alert

scores = zeros(n_xpts, 5);
% the first row is the hypmean used
% the next two are the results (correct) and error bars for correct hyps
% the next two are the results (correct) and error bars for incorrect hyps

corrects = zeros(n_trials, 1);

for expt_ix = 1:n_xpts
disp(expt_ix);
  hypmean = [0.2 * (0.5 * (n_xpts + 1) - expt_ix); 0];
  gendata(hypmean); % kludge alert
  scores(expt_ix,1) = hypmean(1);
  
  for trial = 1:n_trials
    cross_validate;
    res = load('cv_results');
    corrects(trial) = res(1);
  end
  av = sum(corrects) / n_trials;
  vars = (corrects - av) .^ 2;
  scores(expt_ix,2) = av;
  scores(expt_ix,3) = sqrt(sum(vars)/n_trials) / sqrt(n_trials); 
  % I know you can factor this; this way's more illuminating
  
  % average the hyps
  % NB: average in log space (i.e. geometric average)
  hyps = load('gp_hyps');
  hyps = repmat(sum(hyps')' / n_class, 1, n_class);
  dlmwrite('gp_hyps', hyps);
  
  for trial = 1:n_trials
    cross_validate;
    res = load('cv_results');
    corrects(trial) = res(1);
  end
  av = sum(corrects) / n_trials;
  vars = (corrects - av) .^ 2;
  scores(expt_ix,4) = av;
  scores(expt_ix,5) = sqrt(sum(vars)/n_trials) / sqrt(n_trials);
  
  % record results here so we keep partial results if the run is interrupted
  dlmwrite('expt_results', scores(1:expt_ix,:));
end